#pragma once

namespace soft_renderer
{
	template<typename T>
	void WriteData(std::ofstream& os, T val)
	{
		const char* val_buf = (char*)&val;
		os.write(val_buf, sizeof(T));
	}

	template<typename T>
	T ReadData(std::ifstream& is)
	{
		T val;
		char* val_buf = (char*)&val;
		is.read(val_buf, sizeof(T));
		return val;
	}

	template<typename T>
	void ReadData(std::ifstream& is, T& val)
	{
		char* val_buf = (char*)&val;
		is.read(val_buf, sizeof(T));
	}

	template<typename T>
	void swapEndian(T& val)
	{
		char* val_buf = (char*)&val;
		char temp;
		for (int i = 0, j = sizeof(T) - 1; i < j; i++, j--)
		{
			temp = val_buf[i];
			val_buf[i] = val_buf[j];
			val_buf[j] = temp;
			// std::swap(val_buf[i], val_buf[j]);
		}
	}
}

